﻿#include "utils.h"

// 工具函数-二分查找
bool bn_search(unsigned long* vals, unsigned long key, int size, int& out) {
	int l = 0, h = size - 1, mid;
	while (l <= h) {
		mid = (l + h) / 2;
		if (vals[mid] < key) l = mid + 1;
		else if (vals[mid] > key) h = mid - 1;
		else {
			out = mid;
			return true;
		}
	}
	out = l;
	return false;
}